package flexcommon.tests.validators
{
	import flexunit.framework.Assert;
	import flexunit.framework.TestCase;
	
	import flexcommon.validators.RoutingNumberValidator;
	
	import mx.events.ValidationResultEvent;

	/**
	 * @private
	 */
	public class TestRoutingNumberValidator extends TestCase
	{
		private var val:RoutingNumberValidator;
    private var obj:Object; // represents a TextInput control in real scenario
		
		public function TestRoutingNumberValidator(methodName:String=null)
		{
			super(methodName);
		}
		
		public override function setUp():void 
		{
      obj = new Object();
    	val = new RoutingNumberValidator();
      val.source = obj; 
      val.property = "text";
    }
		
		public function testValidCA():void 
		{
      try {
        obj.text = "73159112";
      	val.country = "CA";
        
      	var res:ValidationResultEvent = val.validate( obj, true );
      	Assert.assertEquals( "valid", res.type );
      }
      catch( e:Error ) {
      	trace( "testValidCA >> " + e.getStackTrace() );
      	fail( "testValidCA failed: " + e.message );
      }
    }
	    
	  public function testInvalidCA():void 
		{
      try {
        obj.text = "731596688";
      	val.country = "CA";
        
      	var res:ValidationResultEvent = val.validate( obj, true );
      	Assert.assertEquals( "invalid", res.type );
      }
      catch( e:Error ) {
      	trace( "testInvalidCA >> " + e.getStackTrace() );
      	fail( "testInvalidCA failed: " + e.message );
      }
    }
	    
	  public function testValidUS():void 
		{
      try {
        obj.text = "731596601";
      	val.country = "US";
        
      	var res:ValidationResultEvent = val.validate( obj, true );
      	Assert.assertEquals( "valid", res.type );
      }
      catch( e:Error ) {
      	trace( "testValidUS >> " + e.getStackTrace() );
      	fail( "testValidUS failed: " + e.message );
      }
    }
	    
	  public function testInvalidUS():void 
		{
      try {
        obj.text = "73159668";
      	val.country = "US";
        
      	var res:ValidationResultEvent = val.validate( obj, true );
      	Assert.assertEquals( "invalid", res.type );
      }
      catch( e:Error ) {
      	trace( "testInvalidUS >> " + e.getStackTrace() );
      	fail( "testInvalidUS failed: " + e.message );
      }
    }
	    
	  public function testValidGB():void 
		{
      try {
        obj.text = "731596";
      	val.country = "GB";
        
      	var res:ValidationResultEvent = val.validate( obj, true );
      	Assert.assertEquals( "valid", res.type );
      }
      catch( e:Error ) {
      	trace( "testValidGB >> " + e.getStackTrace() );
      	fail( "testValidGB failed: " + e.message );
      }
    }
	    
	  public function testInvalidGB():void 
		{
      try {
        obj.text = "73159668";
      	val.country = "GB";
        
      	var res:ValidationResultEvent = val.validate( obj, true );
      	Assert.assertEquals( "invalid", res.type );
      }
      catch( e:Error ) {
      	trace( "testInvalidGB >> " + e.getStackTrace() );
      	fail( "testInvalidGB failed: " + e.message );
      }
    }
	    
	  public function testValidOther():void 
		{
      try {
        obj.text = "731596112";
      	val.country = "UA";
        
      	var res:ValidationResultEvent = val.validate( obj, true );
      	Assert.assertEquals( "valid", res.type );
      }
      catch( e:Error ) {
      	trace( "testValidOther >> " + e.getStackTrace() );
      	fail( "testValidOther failed: " + e.message );
      }
    }
	    
	  public function testInvalidOther():void 
		{
      try {
        obj.text = "73";
      	val.country = "UA";
        
      	var res:ValidationResultEvent = val.validate( obj, true );
      	Assert.assertEquals( "invalid", res.type );
      }
      catch( e:Error ) {
      	trace( "testInvalidOther >> " + e.getStackTrace() );
      	fail( "testInvalidOther failed: " + e.message );
      }
    }		
	}
}